#! /bin/bash

# This脚本按时间切换桌面壁纸为某个目录下的文件

IMG_DIR="$HOME/Pictures/p/壁纸1"
COUNTER_FILE=$HOME/.config/plasma-swith-wallpaper

if test -f "$COUNTER_FILE"; then
    COUNTER=`cat $COUNTER_FILE`
else
    COUNTER=0
fi

i=0
files=`ls $IMG_DIR | grep -E -i '\.(jpg|jpeg|png)$'`
filec=`echo "$files" | wc -l`
IFS=$'\n' 
COUNTER=`expr $COUNTER % $filec`

# IFS=$'\n' 
a=($files)
plasma-apply-wallpaperimage "$IMG_DIR/${a[COUNTER]}"

((COUNTER++))
echo $COUNTER > $COUNTER_FILE
